package com.licky.file.controller;

import com.licky.file.utils.MinioUtils;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping(value = "/file")
public class FileController {

    @Value("${minio.bucketName}")
    private String bucketName;

    @Resource
    private MinioUtils minioUtils;


    @RequestMapping(value = "/upload")
    public String uploadFile(@RequestParam("file") MultipartFile file) throws IOException {
        String url = minioUtils.minioUpload(file, file.getOriginalFilename(), bucketName);
        return url;
    }

    @RequestMapping(path = "/download")
    public void downloadFile(@RequestParam("fileName") String fileName, HttpServletResponse response) {
        minioUtils.downloadFile(bucketName, fileName, response);
    }

}
